package impl.defaultImpl;

import design.CalendarBuilder;
import design.entity.Standard;
import ics.nodes.Calendar;
import ics.nodes.VAlarm;
import ics.nodes.VEvent;
import ics.nodes.event.DTEnd;
import ics.nodes.event.DTStart;
import ics.nodes.event.Summary;
import ics.nodes.icalendar.*;
import ics.nodes.valarm.Action;
import ics.nodes.valarm.Trigger;
import org.apache.poi.ss.formula.functions.T;

import java.awt.*;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;

/**
 * @ClassName DefaultCalendarBuilder .java
 * @Description empty
 * @Author LiuJinyu
 * @Date 2023/4/3 9:00
 * @Version 1.0
 */

public class DefaultCalendarBuilder extends CalendarBuilder {

    Calendar calendar = null;

    @Override
    public String DataToString(List<Standard> standards) {
        buildCalendarTitle();
        builderEvent(standards);
        return this.calendar.toString();
    }

    public void buildCalendarTitle() {
        calendar = new Calendar();
        calendar.add(new ProId());
        calendar.add(new Version());
        calendar.add(new Calscale());
        calendar.add(new Method());
        calendar.add(new ICalClass());
    }

    public void builderEvent(List<Standard> standards){
        VEvent vEvent = null;
        DTStart start = null;
        DTEnd end = null;
        Summary summary =  null;
        VAlarm vAlarm = new VAlarm();
        Action action = new Action();
        Trigger trigger = new Trigger(0);
        vAlarm.add(action);
        vAlarm.add(trigger);
        for(Standard standard : standards){
            vEvent = new VEvent();
            start = new DTStart(ZonedDateTime.of(standard.getDate(),standard.getBeginTime(), ZoneId.of("Asia/Chongqing")).toInstant());
            end = new DTEnd(ZonedDateTime.of(standard.getDate(),standard.getEndTime(), ZoneId.of("Asia/Chongqing")).toInstant());
            summary = new Summary(standard.getContent());
            vEvent.add(start);
            vEvent.add(end);
            vEvent.add(summary);
            vEvent.add(vAlarm);
            calendar.add(vEvent);
        }
    }

}
